<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>Tab Bar Tests</title>
<link href="../../../themes/iphone/iphone.css" rel="stylesheet"/>
<script type="text/javascript" src="../../../../../dojo/dojo.js"
	data-dojo-config="parseOnLoad: true"></script>

<script language="JavaScript" type="text/javascript">
	require([
		"dojo/dom-construct", // dojo.place
		"dojo/ready", // dojo.ready
		"dijit/registry",  // dijit.byId
		"doh/runner",	//doh functions
		"dojox/mobile/TabBar",
		"dojox/mobile/TabBarButton",
		"dojox/mobile",				// This is a mobile app.
		"dojox/mobile/View",		// This mobile app uses mobile view
		"dojox/mobile/compat",		// This mobile app supports running on desktop browsers
		"dojox/mobile/parser"		// This mobile app uses declarative programming with fast mobile parser
	], function(domConst, ready, registry, runner, TabBar, TabBarButton){

		function _assertCorrectTabBar(tabBar){
			var tabBarButton = registry.byId(tabBar.domNode.children[0].id);
			runner.assertNotEqual(null, tabBarButton);
			
			var tabBarWidth = tabBar.domNode.clientWidth;
			var tabBarButtonWidth = tabBarButton.domNode.clientWidth;
			var tabBarButtonMarginRight = parseInt(tabBarButton.domNode.style.marginRight);
			var actualOffsetLeft = Math.floor((tabBarWidth - tabBarButtonWidth) / 2);

			var offsetLeft = tabBar.domNode.children[0].offsetLeft;
			var clientWidth = tabBar.domNode.clientWidth;
			runner.assertTrue( (((actualOffsetLeft *0.95) < offsetLeft) && (offsetLeft < (actualOffsetLeft *1.05))) || (offsetLeft <= 6), "expected: " +actualOffsetLeft + "+-5% but got " + offsetLeft + tabBar.toString());
		}

		function _createTabBarDeclaratively(tabBarId){
			return registry.byId(tabBarId);
		};
		
		function _createTabBarProgrammatically(placeHolderId){
			var tabBar = new TabBar();
			var tabBarButton = new TabBarButton({label:"Tab Bar Button",icon1:"../../images/tab-icon-16.png",icon2:"../../images/tab-icon-16h.png",selected:true});
			runner.assertNotEqual(null, tabBarButton, "id=" + placeHolderId);
			tabBar.addChild(tabBarButton);
			domConst.place(tabBar.domNode, placeHolderId, "replace");
			tabBar.startup();
			return tabBar;
		};
		
		function _createTabBarProgrammaticallyWithSourceNodeReference(tabBarId){
			var tabBar = new TabBar({}, tabBarId);
			var tabBarButton = new TabBarButton({label:"Tab Bar Button",icon1:"../../images/tab-icon-16.png",icon2:"../../images/tab-icon-16h.png",selected:true});
			runner.assertNotEqual(null, tabBarButton, "id=" + tabBarId);
			tabBar.addChild(tabBarButton);
			tabBar.startup();
			return tabBar;
		};

		function _showView2(){
			var view1 = registry.byId("view1");
			view1.performTransition("view2", 1, "none");
		};

		ready(function(){
			runner.register("dojox.mobile.test.doh.TabBarTests", [
				function testInView1(){
					var tabBar1 = _createTabBarDeclaratively("view1-tabBar1");
					tabBar1.resize();
			
					var tabBar2 = _createTabBarProgrammatically("view1-tabBar2");
					var tabBar3 = _createTabBarProgrammaticallyWithSourceNodeReference("view1-tabBar3");
					
					_assertCorrectTabBar(tabBar1);
					_assertCorrectTabBar(tabBar2);
					_assertCorrectTabBar(tabBar3);
				},
				function testInView2(){
					var tabBar1 = _createTabBarDeclaratively("view2-tabBar1");
					var tabBar2 = _createTabBarProgrammatically("view2-tabBar2");
					var tabBar3 = _createTabBarProgrammaticallyWithSourceNodeReference("view2-tabBar3");
					
					_showView2();
					
					_assertCorrectTabBar(tabBar1);
					_assertCorrectTabBar(tabBar2);
					_assertCorrectTabBar(tabBar3);				
				}
			]);
			runner.run();
		});
	})
</script>
</head>
<body>
	<div id="view1" data-dojo-type="dojox.mobile.View" selected="true">
		<h1>View 1</h1>
		<ul id="view1-tabBar1" data-dojo-type="dojox.mobile.TabBar">
			<li id="view1-tabBarButton" data-dojo-type="dojox.mobile.TabBarButton" label="Tab Bar Button" icon1="../../images/tab-icon-16.png" icon2="../../images/tab-icon-16h.png" selected=true></li>
		</ul>
		<div id="view1-tabBar2"></div>
		<ul id="view1-tabBar3"></ul>		
	</div>
	<div id="view2" data-dojo-type="dojox.mobile.View">
		<h1>View 2</h1>
		<ul id="view2-tabBar1" data-dojo-type="dojox.mobile.TabBar">
			<li id="view2-tabBarButton" data-dojo-type="dojox.mobile.TabBarButton" icon1="../../images/tab-icon-16.png" icon2="../../images/tab-icon-16h.png" selected="true">Tab Bar Button</li>
		</ul>
		<div id="view2-tabBar2"></div>
		<ul id="view2-tabBar3"></ul>		
	</div>
</body>
</html>
